﻿CREATE PROCEDURE [dbo].[usp_select_Reports_AlertHistoryOverTime]
(
   @StartDate			varchar(25)      = '2000/1/1'   
   ,@EndDate			varchar(25)      = '2010/12/31'   
   ,@Debug              bit              = 0
)
AS

SET NOCOUNT ON;

-- Bootstrap
DECLARE @DebugPrefix       varchar(10)
DECLARE @ErrorCode         int

SET @ErrorCode          = 0;
SET @DebugPrefix        = '>>> DEBUG: '


SELECT
	[Application],
	COUNT([Application]) AS AlertCount,
	CONVERT(VARCHAR, AlertSubscriptionHistory.[InsertedDate], 101) AS AlertDate
FROM	AlertSubscriptionHistory
INNER JOIN AlertHistory on AlertSubscriptionHistory.AlertHistoryId=AlertHistory.AlertHistoryId
WHERE	AlertSubscriptionHistory.InsertedDate BETWEEN @StartDate and @EndDate
GROUP BY [Application], CONVERT(VARCHAR, AlertSubscriptionHistory.[InsertedDate], 101)
ORDER BY [Application], CONVERT(VARCHAR, AlertSubscriptionHistory.[InsertedDate], 101)


SET NOCOUNT OFF;
